home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / os2 / cenvi2.arj / FILEIO.LIB < prev    next >
Text File  |  1993-11-14  |  5KB  |  112 lines

  1. // SCSI.lib
  2.  
  3. #define  _FILEIO_LIB   1
  4.  
  5. DosOpen(FileName,retFileHandle,retActionTaken,FileSize,FileAttribute,
  6.         OpenFlag,OpenMode,EABuf)
  7.    // FileName: ascii string specifyin file to open
  8.    // retFileHandle: return unique file handle
  9.    // retActionTaken: return action taken on succesful open; one of these:
  10.       #define FILE_EXISTED    1  // File already existed
  11.       #define FILE_CREATED    2  // File was created
  12.       #define FILE_TRUNCATED  3  // File existed and was replaced by new file
  13.    // FileSize: should be zero unsless creating or overwriting; sets new file size
  14.    // FileAttribute: Apply only when creating file, OR of these bits:
  15.       #define FILE_NORMAL     0x00
  16.       #define FILE_READONLY   0x01
  17.       #define FILE_HIDDEN     0x02
  18.       #define FILE_SYSTEM     0x04
  19.       #define FILE_DIRECTORY  0x10
  20.       #define FILE_ARCHIVED   0x20
  21.    // OpenFlag: Action to take depending on whether file exists
  22.       #define OPEN_ACTION_FAIL_IF_EXISTS     0x00
  23.       #define OPEN_ACTION_OPEN_IF_EXISTS     0x01
  24.       #define OPEN_ACTION_REPLACE_IF_EXISTS  0x02
  25.       #define OPEN_ACTION_FAIL_IF_NEW        0x00
  26.       #define OPEN_ACTION_CREATE_IF_NEW      0x10
  27.    // OpenMode: OR of following flags
  28.       #define OPEN_ACCESS_READONLY           0x0000   // Read only for this process
  29.       #define OPEN_ACCESS_WRITEONLY          0x0001   // Write-only for this process
  30.       #define OPEN_ACCESS_READWRITE          0x0002   // Read and write access for this process
  31.       #define OPEN_SHARE_DENYREADWRITE       0x0010   // Deny read/write access to other process
  32.       #define OPEN_SHARE_DENYWRITE           0x0020   // Deny write access to other process
  33.       #define OPEN_SHARE_DENYREAD            0x0030   // Deny read access to other process
  34.       #define OPEN_SHARE_DENYNONE            0x0040   // Deny neither read nor write to other processes
  35.       #define OPEN_FLAGS_NOINHERIT           0x0080   // file handle private to current process
  36.       #define OPEN_FLAGS_NO_LOCALITY         0x0000   // No locality known
  37.       #define OPEN_FLAGS_SEQUENTIAL          0x0100   // Mainly sequential access
  38.       #define OPEN_FLAGS_RANDOM              0x0200   // Mainly random access
  39.       #define OPEN_FLAGS_RANDOMSEQUENTIAL    0x0300   // Random with some locality
  40.       #define OPEN_FLAGS_NO_CACHE            0x1000   // don't cache data IO
  41.       #define OPEN_FLAGS_FAIL_ON_ERROR       0x2000   // report to caller, not trhough system critical handler
  42.       #define OPEN_FLAGS_WRITE_THROUGH       0x4000   // write before synchronous write returns
  43.       #define OPEN_FLAGS_DASD                0x8000   // filename is a drive (e.g. C:)
  44.       #define OPEN_FLAGS_NONSPOOLED          0x40000
  45.    // EABuf: Read and write extended attrib buffer to this blob if not NULL
  46.    // Return: 0 if no error, else error code
  47. {
  48.    #define ORD_DOS32OPEN   273
  49.    rc = DynamicLink("doscalls",ORD_DOS32OPEN,BIT32,CDECL,
  50.                     FileName,_doFileHandle,_doActionTaken,FileSize,FileAttribute,
  51.                     OpenFlag,OpenMode,EABuf);
  52.    if ( 0 == rc ) {
  53.       retFileHandle = _doFileHandle;
  54.       retActionTaken = _doActionTaken;
  55.    }
  56.    return(rc);
  57. }
  58.  
  59.  
  60. DosClose(FileHandle)
  61.    // FileHandle: previous value returned from
  62.    // Return: 0 if no error, else error code
  63. {
  64.    #define ORD_DOS32CLOSE  257
  65.    return DynamicLink("doscalls",ORD_DOS32CLOSE,BIT32,CDECL,FileHandle);
  66. }
  67.  
  68. DosRead(FileHandle,BufferArea,BufferLength,BytesRead)
  69.    // FileHandle: previous value returned from
  70.    // BufferArea: where to read to; this will make sure it's big enough
  71.    // BufferLength: maximum size of buffer area to read to
  72.    // BytesRead: Return number of bytes read
  73.    // Return: 0 if no error, else error code
  74. {
  75.    if ( BufferLength < 1 ) {
  76.       BytesRead = 0;
  77.       _ret = 0;
  78.    } else {
  79.       // Make sure that BufferArea is big enough
  80.       if ( !defined(BufferArea)  ||  BLObSize(BufferArea) < BufferLength )
  81.          BLObSize(BufferArea,BufferLength);
  82.  
  83.       #define ORD_DOS32READ   281
  84.       BLObPut(_BytesRead,0,0,UWORD32);
  85.       _ret = DynamicLink("doscalls",ORD_DOS32READ,BIT32,CDECL,
  86.                          FileHandle,BufferArea,BufferLength,_BytesRead);
  87.       BytesRead = BLObGet(_BytesRead,0,UWORD32);
  88.    }
  89.    return _ret;
  90. }
  91.  
  92. DosWrite(FileHandle,BufferArea,BufferLength,BytesWritten)
  93.    // FileHandle: previous value returned from
  94.    // BufferArea: where to read bytes from
  95.    // BufferLength: how many bytes to write
  96.    // BytesRead: Return number of bytes actually written
  97.    // Return: 0 if no error, else error code
  98. {
  99.    if ( BufferLength < 1 ) {
  100.       BytesWritten = 0;
  101.       _ret = 0;
  102.    } else {
  103.       #define ORD_DOS32WRITE  282
  104.       BLObPut(_BytesWritten,0,0,UWORD32);
  105.       _ret = DynamicLink("doscalls",ORD_DOS32WRITE,BIT32,CDECL,
  106.                          FileHandle,BufferArea,BufferLength,_BytesWritten);
  107.       BytesWritten = BLObGet(_BytesWritten,0,UWORD32);
  108.    }
  109.    return _ret;
  110. }
  111.  
  112.